define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($, undefined, Backend, Table, Form,Layer) {
    var Controller = {
        index: function () {
            var team = false;//判断是否团队数据查询
            var table = $("#table");
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'crm/allot/index',
                    add_url: 'crm/buser/add',
                    edit_url: 'crm/buser/edit/type/2',
                    import_url: 'crm/buser/import',
                    multi_url: 'crm/allot/multi',
                    table: 'allot',
                },
                queryParams: function (params) {
                    // 自定义搜索条件
                    var filter = params.filter ? JSON.parse(params.filter) : {};
                    var op = params.op ? JSON.parse(params.op) : {};
                    //filter.后跟的是在ajax里使用的名称
                    if($('#team').find('.active').find('a').attr('data-value')){
                        params['team'] = $('#team').find('.active').find('a').attr('data-value');
                    }
                    params['wf_group_id'] = $('#group').val();
                    params['wf_admin_id'] = $('#admin_id').val();
                    params.filter = JSON.stringify(filter);
                    params.op = JSON.stringify(op);
                    return params;
                }
            });

            //当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                //这里我们手动设置底部的值
                $('#qiCount').text(data.qiCount)
            });
          /*  table.on('click-row.bs.table',function (e,data) {
                Layer.open({
                    type: 2,
                    content:[ 'http://test.crm.com/admin_d75KABNWtWf8888888.php/crm/buserfolloe/index/type/3/add/add/ids/'+data['id'],'no'],
                    anim: 3,
                    offset: 'rt',
                    title: false,
                    area: ['1300px','1300px'],
                    shade: [0.2, '#eeeeee']
                });
                $('.layui-layer-shade').bind('click',function () {
                    Layer.closeAll();
                })
            })*/
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                searchFormTemplate: 'customformtpl',
                pageSize: 10,
                pageList: [10, 25],
                columns: [
                    [
                        {checkbox: true},
                        {field: 'expire_date', title: __('Expire_date'),operate:false, addclass:'datetimerange'},
                        {field: 'qi', title: __('分配倒计时'),operate:false},
                        {field: 'followuptime', title: __('Followuptime'),operate:false, addclass:'datetimerange'},
                        {field: 'buser.username', title: __('Buser.username'), operate:'like'},
                        {field: 'buser.contacts', title: __('Buser.contacts'), operate:'like'},
                        {field: 'product.product', title: __('Product.product'), operate:'like'},
                        {field: 'admin.nickname', title: __('Admin.nickname'), operate:'like'},
                        {field: 'button', title: __('客户信息'), table: table, buttons: [
                                {
                                    name: '工商信息', text: '工商信息', title: '工商信息', icon: 'fa fa-flash',
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-success', url: 'crm/buserinfo/index',
                                    callback:function(data){
                                    },hidden:function (val) {
                                        if(val['buser']['pinname']){
                                            return false;
                                        }else {
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: '舆情信息', text: '舆情信息', title: '舆情信息', icon: 'fa fa-flash',
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-info', url: 'crm/buserinfo/sentiment',
                                    callback:function(data){

                                    }
                                }
                            ], operate:false, formatter: Table.api.formatter.buttons},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('按钮组'),
                            table: table,
                            events: Table.api.events.operate,
                            operate:false,
                            buttons: [
                                {
                                    name: '跟进进度',
                                    text: __('跟进进度'),
                                    title: __('跟进进度'),
                                    extend:'title="跟进进度"',
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-warning',
                                    icon: 'fa fa-pencil-square-o',
                                    url: 'crm/Buserfolloe/add',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row['status']!=6&&admin_nickname==row['admin']['nickname']){
                                            return true;
                                        }else {
                                            return false
                                        }
                                    },
                                },
                              /*  {
                                    name: 'expired_allot',
                                    text: __('分配负责人'),
                                    title: __('分配负责人'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'crm/allot/expired_allot',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    },
                                    hidden:function (value) {
                                        if(value['fen']=='hide'){
                                            return true;
                                        }
                                    }
                                },*//* {
                                    name: '推荐产品',
                                    text: __('推荐产品'),
                                    title: __('推荐产品'),
                                    extend:'title="推荐产品"',
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-info',
                                    icon: 'fa fa-shopping-cart',
                                    url: 'crm/allot/push_products',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;

                                    },
                                    hidden:function(value,row){
                                        if(value['status']!=6){
                                            //当前任务没有完成，或者
                                            return true;
                                        }else if(admin_group_id!=1&&admin_group_id!=2){
                                            //不是超管和销售部经理
                                            return true;
                                        }
                                    }
                                },*/
                                {
                                    name: '续约',
                                    text: __('续约'),
                                    title: __('续约'),
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-success',
                                    icon: 'fa fa-jpy',
                                    url: 'crm/Cooperation/add',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(admin_group_id==1||admin_group_id==2){
                                            //超级权限
                                            if(row['status']==6){
                                                return true
                                            }else {
                                                return false
                                            }
                                        }else if(row['status']==6&&admin_nickname==row['admin']['nickname']){
                                            //
                                            return true
                                        }else {
                                            return false
                                        }
                                    }
                                }, {
                                    name: '跟进记录',
                                    text: __('跟进记录'),
                                    title: __('跟进记录'),
                                    extend:'title="跟进记录"',
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-danger',
                                    icon: 'fa fa-pencil-square-o',
                                    url: 'crm/buserfolloe/index/type/3',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },{
                                    name: '续费记录',
                                    text: __('续费记录'),
                                    title: __('续费记录'),
                                    extend:'title="推荐产品"',
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-warning',
                                    icon: 'fa fa-pencil-square-o',
                                    url: 'crm/cooperation/index',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row['status']==6){
                                            //签约成功
                                            return true;
                                        }else {
                                            return false
                                        }
                                    }
                                },{
                                    name: '投入公海',
                                    text: __('投入公海'),
                                    title: __('投入公海'),
                                    extend:'title="投入公海"',
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-warning',
                                    icon: 'fa fa-pencil-square-o',
                                    url: 'crm/highseas/add',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row['status']!=6&&admin_nickname==row['admin']['nickname']&&row['highlist']==1){
                                            return true;
                                        }else {
                                            return false
                                        }
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.buttons
                        },
                        {field: 'highlist', title: __('Highlist'),searchList: {"1":__('highlist 1'),"2":__('highlist 2')}, formatter: Table.api.formatter.status},
                        {field: 'buser.qq', title: __('Buser.qq'), operate:false},
                        {field: 'buser.wechat', title: __('Buser.wechat'), operate:false},
                        {field: 'buser.mobile', title: __('Buser.mobile'), operate:false},
                        {field: 'buser.email', title: __('Buser.email'), operate:false},
                        {field: 'status', title: __('status'),searchList: {"0":__('status 0'),"1":__('status 1'),"2":__('status 2'),"3":__('status 3'),"4":__('status 4'),"5":__('status 5'),"6":__('status 6')}, formatter: Table.api.formatter.status},
                        {field: 'buser.gender', title: __('Buser.gender'),operate:false,searchList: {"1":__('Gender 1'),"2":__('Gender 2')}, formatter: Table.api.formatter.status},
                        {field: 'buser.hobby', title: __('Buser.hobby'),operate:false},
                        {field: 'buser.birthday', title: __('Buser.birthday'),operate:false, addclass:'datetimerange'},
                        {field: 'buser.station', title: __('Buser.station'),operate:false},
                        {field: 'typelist', title: __('Typelist'), searchList: {"1":__('Typelist 1'),"2":__('Typelist 2'),"3":__('Typelist 3'),"4":__('Typelist 4')}, formatter: Table.api.formatter.normal},
                        {field: 'qilist', title: __('Qilist'), searchList: {"1":__('Qilist 1'),"2":__('Qilist 2'),"3":__('Qilist 3')}, formatter: Table.api.formatter.normal},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            formatter: function (value, row, index) {
                                var that = $.extend({}, this);
                                var table = $(that.table).clone(true);
                                /* if(row.status!=1||admin_group_id!=3){
                                     //审核过的数据和不是销售人员隐藏编辑按钮
                                     $(table).data("operate-edit", null);
                                 }*/
                                $(table).data("operate-del", null);
                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);
                            },
                        }
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
            //这里需要手动为Form绑定上元素事件
            Form.api.bindevent($("form#cxselectform"));
            /**
             * 查询可以分配的用户
             */
            $(".distribution").bind('click',function(){
                parent.Fast.api.open("crm/allot/distribution", __('Choose'), {
                    callback: function (data) {

                    }
                });
                return false;
            });
            /**
             * 团队查询
             */
            $('.panel-heading a[data-toggle="tab"]').on('click',function () {
                var options = table.bootstrapTable('getOptions');
                options.pageNumber = 1;//初始化分页
            })
            /**
             * 查询可以分配的用户
             */
            $(".product").bind('click',function(){
                parent.Fast.api.open("crm/allot/product", __('Choose'), {
                    callback: function (data) {

                    }
                });
                return false;
            });
            /**
             * 查询待跟进的网贷客户
             */
            $(".followup").bind('click',function(){
                parent.Fast.api.open("crm/allot/followup", __('Choose'), {
                    callback: function (data) {

                    }
                });
                return false;
            });
            /**
             * 是否查询团队数据
             */
            $('.team').click(function () {
                var link = $(this);
                var type = link.attr('data-type');
                if(type==1){
                    $('.group_select').hide();
                }else {
                    $('.group_select').show();
                }
            })
          /*  require(['upload'], function (Upload) {
                Upload.api.plupload($('.btn-stock-file'), function (data, ret) {
                    Fast.api.ajax({
                        url: 'product/stock_import',
                        data: {file: data.url},
                    }, function (data, ret) {
                        //table.bootstrapTable('refresh');
                    });
                });
            });*/
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        //分配联系人
        expired_allot:function(){
          Controller.api.bindevent();

        },
        push_products:function () {
            Controller.api.bindevent();
        },
        /**
         * 可分配客户查询
         */
        distribution:function () {
            Table.api.init({
                extend: {
                    index_url: 'crm/allot/distribution',
                    add_url: 'crm/allot/add',
                    edit_url: '',
                    del_url: '',
                    multi_url: '',
                    table: 'allot',
                },
                queryParams: function (params) {
                    // 自定义搜索条件
                    var filter = params.filter ? JSON.parse(params.filter) : {};
                    var op = params.op ? JSON.parse(params.op) : {};
                    //filter.后跟的是在ajax里使用的名称
                    if($('#team').find('.active').find('a').attr('data-value')){
                        params['team'] = $('#team').find('.active').find('a').attr('data-value');
                    }
                    params['wf_group_id'] = $('#group').val();
                    params['wf_admin_id'] = $('#admin_id').val();
                    params.filter = JSON.stringify(filter);
                    params.op = JSON.stringify(op);
                    return params;
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                searchFormTemplate: 'customformtpl',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'expire_date', title: __('Expire_date'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'qi', title: __('分期倒计时')},
                        {field: 'allot_date', title: __('Allot_date'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'followuptime', title: __('Followuptime'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'buser.username', title: __('Buser.username'), operate:'like'},
                        {field: 'buser.contacts', title: __('Buser.contacts')},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('按钮组'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'expired_allot',
                                    text: __('分配负责人'),
                                    title: __('分配负责人'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'crm/allot/expired_allot',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    },
                                    hidden:function (value) {
                                        if(value['fen']=='hide'){
                                            return true;
                                        }
                                    }
                                }, {
                                    name: '推荐产品',
                                    text: __('推荐产品'),
                                    title: __('推荐产品'),
                                    extend:'title="推荐产品"',
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-info',
                                    icon: 'fa fa-list',
                                    url: 'crm/allot/push_products',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;

                                    },
                                    hidden:function(value,row){
                                        if(value['status']!=6){
                                            //当前任务没有完成，或者
                                            return true;
                                        }else if(admin_group_id!=1&&admin_group_id!=2){
                                            //不是超管和销售部经理
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: '合作备案', text: '合作备案', title: '合作备案', icon: 'fa fa-flash',
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-success', url: 'crm/Cooperation/add',
                                    callback:function(data){
                                    },  hidden:function(value,row){
                                        if(value['status']!=6||value['beilist']==2){
                                            //当前任务没有完成，或者已经备案
                                            return true;
                                        }
                                    }
                                },

                            ],
                            formatter: Table.api.formatter.buttons
                        },
                        {field: 'buser.qq', title: __('Buser.qq'), operate:'like'},
                        {field: 'buser.wechat', title: __('Buser.wechat'), operate:'like'},
                        {field: 'buser.mobile', title: __('Buser.mobile'), operate:'like'},
                        {field: 'buser.email', title: __('Buser.email'), operate:'like'},
                        {field: 'status', title: __('status'),searchList: {"0":__('status 0'),"1":__('status 1'),"2":__('status 2'),"3":__('status 3'),"4":__('status 4'),"5":__('status 5'),"6":__('status 6')}, formatter: Table.api.formatter.status},
                        {field: 'buser.gender', title: __('Buser.gender'),searchList: {"1":__('Gender 1'),"2":__('Gender 2')}, formatter: Table.api.formatter.status},
                        {field: 'buser.birthday', title: __('Buser.birthday'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'buser.hobby', title: __('Buser.hobby')},
                        {field: 'buser.station', title: __('Buser.station')},
                        {field: 'admin.nickname', title: __('Admin.nickname'), operate:'like'},
                        {field: 'product.product', title: __('Product.product'), operate:'like'},
                        {field: 'typelist', title: __('Typelist'), searchList: {"1":__('Typelist 1'),"2":__('Typelist 2'),"3":__('Typelist 3'),"4":__('Typelist 4')}, formatter: Table.api.formatter.normal},
                        {field: 'qilist', title: __('Qilist'), searchList: {"1":__('Qilist 1'),"2":__('Qilist 2'),"3":__('Qilist 3')}, formatter: Table.api.formatter.normal},

                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        /**
         * 已签约客户推荐其他产品
         */
        product:function () {
            Table.api.init({
                extend: {
                    index_url: 'crm/allot/product',
                    table: 'allot',
                },
                queryParams: function (params) {
                    // 自定义搜索条件
                    var filter = params.filter ? JSON.parse(params.filter) : {};
                    var op = params.op ? JSON.parse(params.op) : {};
                    //filter.后跟的是在ajax里使用的名称
                    params.filter = JSON.stringify(filter);
                    params.op = JSON.stringify(op);
                    return params;
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                searchFormTemplate: 'customformtpl',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'username', title: __('Buser.username'), operate:'like'},
                        {field: 'contacts', title: __('Buser.contacts'), operate:'like'},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('按钮组'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                               {
                                    name: '推荐产品',
                                    text: __('推荐产品'),
                                    title: __('推荐产品'),
                                    extend:'title="推荐产品"',
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-info',
                                    icon: 'fa fa-list',
                                    url: 'crm/allot/push_products',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;

                                    }
                                }
                            ],
                            formatter: Table.api.formatter.buttons
                        },
                        {field: 'qq', title: __('Buser.qq'), operate:'like'},
                        {field: 'wechat', title: __('Buser.wechat'), operate:'like'},
                        {field: 'mobile', title: __('Buser.mobile'), operate:'like'},
                        {field: 'email', title: __('Buser.email'), operate:'like'},
                        {field: 'gender', title: __('Buser.gender'),searchList: {"1":__('Gender 1'),"2":__('Gender 2')}, formatter: Table.api.formatter.status},
                        {field: 'birthday', title: __('Buser.birthday'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'hobby', title: __('Buser.hobby'), operate:false},
                        {field: 'station', title: __('Buser.station')},
                   ]
                ]
            });
            Table.api.bindevent(table);
        }, finance_user: function () {
            /*金融类客户分配数据*/
            Table.api.init({
                extend: {
                    index_url: 'crm/allot/finance_user',
                    add_url: 'crm/bkuser/add',
                    edit_url: 'crm/bkuser/edit/type/2',
                  /*  del_url: 'crm/allot/del',*/
                    import_url: 'crm/bkuser/import',
                   /* multi_url: 'crm/allot/multi',*/
                    table: 'allot',
                },
                queryParams: function (params) {
                    // 自定义搜索条件
                    var filter = params.filter ? JSON.parse(params.filter) : {};
                    var op = params.op ? JSON.parse(params.op) : {};
                    //filter.后跟的是在ajax里使用的名称
                    if($('#team').find('.active').find('a').attr('data-value')){
                        params['team'] = $('#team').find('.active').find('a').attr('data-value');
                    }
                    params['wf_group_id'] = $('#group').val();
                    params['wf_admin_id'] = $('#admin_id').val();
                    params.filter = JSON.stringify(filter);
                    params.op = JSON.stringify(op);
                    return params;
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                searchFormTemplate: 'customformtpl',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'bkuser.company', title: __('Bkuser.company'),operate:false},
                        {field: 'bkuser.username', title: __('Bkuser.username'),operate:false},
                        {field: 'bkuser.english_name', title: __('Bkuser.english_name'),operate:false},
                        {field: 'qi', title: __('分配倒计时'),operate:false},
                        {field: 'bkuser.company_address', title: __('Bkuser.company_address'),operate:false},
                        {field: 'bkuser.company_url', title: __('Bkuser.company_url'), operate:'like'},
                        {field: 'bkuser.office_tel', title: __('Bkuser.office_tel'), operate:'like'},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('按钮组'),
                            table: table,
                            events: Table.api.events.operate,
                            operate:false,
                            buttons: [
                                {
                                    name: '跟进进度',
                                    text: __('跟进进度'),
                                    title: __('跟进进度'),
                                    extend:'title="跟进进度"',
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-warning',
                                    icon: 'fa fa-pencil-square-o',
                                    url: 'crm/Buserfolloe/add',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row['status']!=6&&admin_nickname==row['admin']['nickname']){
                                            return true;
                                        }else {
                                            return false
                                        }
                                    },
                                },
                                {
                                    name: 'expired_allot',
                                    text: __('分配负责人'),
                                    title: __('分配负责人'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'crm/allot/expired_allot',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    },
                                    hidden:function (value) {
                                        if(value['fen']=='hide'){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: '合作备案', text: '合作备案', title: '合作备案', icon: 'fa fa-flash',
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-success', url: 'crm/Cooperation/add',
                                    callback:function(data){
                                    },  hidden:function(value,row){
                                        if(value['status']!=6||value['beilist']==2){
                                            //当前任务没有完成，或者已经备案
                                            return true;
                                        }
                                    }
                                },{
                                    name: '续约',
                                    text: __('续约'),
                                    title: __('续约'),
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-success',
                                    icon: 'fa fa-jpy',
                                    url: 'crm/Cooperation/add',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(admin_group_id==1||admin_group_id==2){
                                            //超级权限
                                            if(row['status']==6){
                                                return true
                                            }else {
                                                return false
                                            }
                                        }else if(row['status']==6&&admin_nickname!=row['admin']['nickname']){
                                            //已经续约隐藏
                                            return true
                                        }else {
                                            return false
                                        }
                                    }
                                }, {
                                    name: '跟进记录',
                                    text: __('跟进记录'),
                                    title: __('跟进记录'),
                                    extend:'title="跟进记录"',
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-danger',
                                    icon: 'fa fa-pencil-square-o',
                                    url: 'crm/buserfolloe/bk_record',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },{
                                    name: '续费记录',
                                    text: __('续费记录'),
                                    title: __('续费记录'),
                                    extend:'title="推荐产品"',
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-warning',
                                    icon: 'fa fa-pencil-square-o',
                                    url: 'crm/cooperation/index',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row['status']==6){
                                            //签约成功
                                            return true;
                                        }else {
                                            return false
                                        }
                                    }
                                },{
                                    name: '投入公海',
                                    text: __('投入公海'),
                                    title: __('投入公海'),
                                    extend:'title="投入公海"',
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-warning',
                                    icon: 'fa fa-pencil-square-o',
                                    url: 'crm/highseas/add',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row['status']!=6&&admin_nickname==row['admin']['nickname']&&row['highlist']==1){
                                            return true;
                                        }else {
                                            return false
                                        }
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.buttons
                        },
                        {field: 'bkuser.industry', title: __('Bkuser.industry'), operate:false},
                        {field: 'bkuser.companylist', title: __('Bkuser.companylist'), operate:false},
                        {field: 'bkuser.department', title: __('Bkuser.department'), operate:false},
                        {field: 'bkuser.post', title: __('Bkuser.post'), operate:false},
                        {field: 'bkuser.qq', title: __('Bkuser.qq'), operate:false},
                        {field: 'bkuser.wechat', title: __('Bkuser.wechat'), operate:false},
                        {field: 'bkuser.mobile', title: __('Bkuser.mobile'), operate:false},
                        {field: 'bkuser.email', title: __('Bkuser.email'), operate:false},
                        {field: 'status', title: __('status'),searchList: {"0":__('status 0'),"1":__('status 1'),"2":__('status 2'),"3":__('status 3'),"4":__('status 4'),"5":__('status 5'),"6":__('status 6')}, formatter: Table.api.formatter.status},
                        {field: 'bkuser.gender', title: __('Buser.gender'),operate:false,searchList: {"1":__('Gender 1'),"2":__('Gender 2')}, formatter: Table.api.formatter.status},
                        {field: 'admin.nickname', title: __('Admin.nickname'), operate:'like'},
                        {field: 'product.product', title: __('Product.product'), operate:'like'},
                        {field: 'typelist', title: __('Typelist'), searchList: {"1":__('Typelist 1'),"2":__('Typelist 2'),"3":__('Typelist 3'),"4":__('Typelist 4')}, formatter: Table.api.formatter.normal},
                        {field: 'qilist', title: __('Qilist'), searchList: {"1":__('Qilist 1'),"2":__('Qilist 2'),"3":__('Qilist 3')}, formatter: Table.api.formatter.normal},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            formatter: function (value, row, index) {
                                var that = $.extend({}, this);
                                var table = $(that.table).clone(true);
                                /* if(row.status!=1||admin_group_id!=3){
                                     //审核过的数据和不是销售人员隐藏编辑按钮
                                     $(table).data("operate-edit", null);
                                 }*/
                                $(table).data("operate-del", null);
                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);
                            }
                        }
                    ]
                ]
            });
            //当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                //这里我们手动设置底部的值
                console.log(data);
                $('#qiCount').text(data.qiCount)
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
            //这里需要手动为Form绑定上元素事件
            Form.api.bindevent($("form#cxselectform"));
            /**
             * 查询可以分配的用户
             */
            $(".distribution").bind('click',function(){
                parent.Fast.api.open("crm/allot/distribution", __('Choose'), {
                    callback: function (data) {

                    }
                });
                return false;
            });
            /**
             * 查询可以分配的用户
             */
            $(".product").bind('click',function(){
                parent.Fast.api.open("crm/allot/product", __('Choose'), {
                    callback: function (data) {

                    }
                });
                return false;
            });
            /**
             * 是否查询团队数据
             */
            $('.team').click(function () {
                var link = $(this);
                var type = link.attr('data-type');
                if(type==1){
                    $('.group_select').hide();
                }else {
                    $('.group_select').show();
                }
            })

        },
        /**
         * 待跟进的网贷客户
         */
        followup:function () {
            Table.api.init({
                extend: {
                    index_url: 'crm/allot/followup',
                    table: 'allot',
                },
                queryParams: function (params) {
                    // 自定义搜索条件
                    var filter = params.filter ? JSON.parse(params.filter) : {};
                    var op = params.op ? JSON.parse(params.op) : {};
                    //filter.后跟的是在ajax里使用的名称
                    params.filter = JSON.stringify(filter);
                    params.op = JSON.stringify(op);
                    return params;
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                searchFormTemplate: 'customformtpl',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'buser.username', title: __('Buser.username'), operate:'like'},
                        {field: 'product.product', title: __('Product.product'), operate:'like'},
                        {field: 'buser.contacts', title: __('Buser.contacts'), operate:'like'},
                        {field: 'admin.nickname', title: __('Admin.nickname'), operate:'like'},
                        {field: 'qi', title: __('分配倒计时'),operate:false},
                        {field: 'status', title: __('status'),searchList: {"0":__('status 0'),"1":__('status 1'),"2":__('status 2'),"3":__('status 3'),"4":__('status 4'),"5":__('status 5'),"6":__('status 6')}, formatter: Table.api.formatter.status},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('按钮组'),
                            table: table,
                            events: Table.api.events.operate,
                            operate:false,
                            buttons: [
                                {
                                    name: '跟进进度',
                                    text: __('跟进进度'),
                                    title: __('跟进进度'),
                                    extend:'title="跟进进度"',
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-warning',
                                    icon: 'fa fa-pencil-square-o',
                                    url: 'crm/Buserfolloe/add',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row['status']!=6&&admin_nickname==row['admin']['nickname']){
                                            return true;
                                        }else {
                                            return false
                                        }
                                    },
                                }, {
                                    name: '跟进记录',
                                    text: __('跟进记录'),
                                    title: __('跟进记录'),
                                    extend:'title="跟进记录"',
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-danger',
                                    icon: 'fa fa-pencil-square-o',
                                    url: 'crm/buserfolloe/index/type/3',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },{
                                    name: '投入公海',
                                    text: __('投入公海'),
                                    title: __('投入公海'),
                                    extend:'title="投入公海"',
                                    classname: 'btn btn-xs btn-primary btn-dialog btn-warning',
                                    icon: 'fa fa-pencil-square-o',
                                    url: 'crm/highseas/add',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row['status']!=6&&admin_nickname==row['admin']['nickname']&&row['highlist']==1){
                                            return true;
                                        }else {
                                            return false
                                        }
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.buttons
                        },
                        {field: 'highlist', title: __('Highlist'),searchList: {"1":__('highlist 1'),"2":__('highlist 2')}, formatter: Table.api.formatter.status},
                        {field: 'buser.qq', title: __('Buser.qq'), operate:'like'},
                        {field: 'buser.wechat', title: __('Buser.wechat'), operate:'like'},
                        {field: 'buser.mobile', title: __('Buser.mobile'), operate:'like'},
                        {field: 'buser.email', title: __('Buser.email'), operate:'like'},
                        {field: 'buser.gender', title: __('Buser.gender'),searchList: {"1":__('Gender 1'),"2":__('Gender 2')}, formatter: Table.api.formatter.status},
                        {field: 'buser.birthday', title: __('Buser.birthday'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'buser.hobby', title: __('Buser.hobby'), operate:'like'},
                        {field: 'buser.station', title: __('Buser.station')},
                    ]
                ]
            });
            Table.api.bindevent(table);
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});